# -*- coding: utf-8 -*-
### required - do no delete
def user(): return dict(form=auth())
def download(): return response.download(request,db)
def call():
    session.forget()
    return service()
### end requires

@auth.requires_login()
def index():
    app_settings = 'app settings'
    record = db(db.settings).select().first()
    #users = db().select(db.users.ALL, orderby=~db.users.join_time)
    #user_number = len(users)
    #last_join_time = users.first().join_time
    #url = "http://www.facebook.com/apps/application.php?id=%s" % current_settings.app_id
    form = SQLFORM(db.settings, record = record,
            labels = {
                'fb_app_id'      : '%s/app id' % app_settings,
                'fb_app_secret'  : '%s/app secret' % app_settings,
                'fb_fan_page' : '%s/fan page url' % app_settings,
                'force_count_number' : 'Force Count',
                'force_count_title' : 'Force Header',
                },
            col3 = {
                'fb_fan_page' : I('requires trailing slash /'),
                'lander' : I('fancy graphic to make them like the page'),
                'header' : I('header graphic or html can be empty if ya want.'),
                'footer': I('footer graphic or html... can be left blank if so please.'),
                'invite_title' : I('Title on top the app request dialog. Max 55 characters'),
                'invite_message' : I('Message sent to invite friend.. probably wanna let them know its a fanpage.'),
                'force_count_number' : I('number of friends to force them to invite'),
                'force_count_title' : I('title of error window if haven\'t invited enough friend'),
                'force_message_before' : I('message to show before the number'),
                'force_message_after' : I('message to show after the number'),
                },
                )
    if form.accepts(request.vars, session):
        response.flash = 'Settings saved!'
    elif form.errors:
        response.flash = 'Please check the error'
    else:
        response.flash = 'Please fill out the fields'
    #return dict(form = form, user_number = user_number, last_join_time = last_join_time)
    return dict(form = form)

def error():
    return dict(message = T("You need to log in first!"))
